/**
 * Copyright (c) 2004-2006, Martin Fiedler
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, 
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 **/
 
#include "common.h"
#include "input.h"
#include "nal.h"
#include "cavlc.h"
#include "params.h"

int main(int argc, char *argv[]) {
  nal_unit unit;
  seq_parameter_set sps;
  pic_parameter_set pps;
  int count;

  if(!input_open("../../../../../input/h264/manitu.264")) return 1;

  for(count=1; get_next_nal_unit(&unit); ++count)
    if(unit.nal_unit_type==7) {
      decode_seq_parameter_set(&sps);
      printf("Sequence Parameter Set:\n  Profile %d Level %d Constraints %d%d%d\n",
        sps.profile_idc,sps.level_idc,sps.constraint_set0_flag,sps.constraint_set1_flag,sps.constraint_set2_flag);
      printf("  ID=0x%08X MaxFrameNum=%d pic_order_cnt_type=%d\n",
        sps.seq_parameter_set_id,sps.MaxFrameNum,sps.pic_order_cnt_type);
      printf("  num_ref_frames=%d gaps_in_frame_num_allowed=%d\n",
        sps.num_ref_frames,sps.gaps_in_frame_num_value_allowed_flag);
      printf("  Dimensions: %dx%d%s\n",
        sps.PicWidthInSamples,sps.FrameHeightInSamples,sps.frame_mbs_only_flag?"":"i");
    } else if(unit.nal_unit_type==8) {
      decode_pic_parameter_set(&pps);
      printf("Picture Parameter Set:\n  ID=0x%08x RefID=0x%08x\n",
        pps.pic_parameter_set_id,pps.seq_parameter_set_id);
      printf("  CABAC=%d pic_order_present=%d\n",
        pps.entropy_coding_mode_flag,pps.pic_order_present_flag);
      printf("  num_slice_groups=%d slice_group_map_type=%d\n",
        pps.num_slice_groups,pps.slice_group_map_type);
      printf("  num_ref_idx_l0_active=%d num_ref_idx_l1_active=%d\n",
        pps.num_ref_idx_l0_active,pps.num_ref_idx_l1_active);
      printf("  weighted_pred=%d weighted_bipred=%d\n",
        pps.weighted_pred_flag,pps.weighted_bipred_idc);
      printf("  pic_init_qp=%d pic_init_qs=%d chroma_qp_offset=%d\n",
        pps.pic_init_qp,pps.pic_init_qs,pps.chroma_qp_index_offset);
      printf("  deblocking_filter_control=%d constrained_intra_pred=%d redundant_pic_cnt=%d\n",
        pps.deblocking_filter_control_present_flag,pps.constrained_intra_pred_flag,pps.redundant_pic_cnt_present_flag);
    }
  
  input_close();
  return 0;
}

